<div class="navigation">
    <a href="/">Главная</a>&nbsp;&nbsp;/&nbsp;&nbsp;<a href="<?= Yii::app()->controller->createUrl('/profile/my_lots'); ?>">Мои Заявки</a>&nbsp;&nbsp;/&nbsp;&nbsp;<a href="<?= Yii::app()->controller->createUrl('/profile/my_lots/add'); ?>" class="nav_active">Добавить Заявку</a>
</div>

<div class="">
    <h1 class="zag">Добавить Заявку</h1>
    <div class="line"> </div>

    <?php if ( $oLot->hasErrors() ) : ?>
    <div class="error">
        <?= CHtml::errorSummary($oLot); ?>
    </div>
    <br />
    <?php endif; ?>

    <form action="<?= Yii::app()->controller->createUrl('/profile/my_lots/add'); ?>" method="post">
        <div>

            <div style="margin-top: 15px;">
                <div style="margin: 5px;">
                    <label for="lot_tariff_plan" class="inline"><span>Заявку использовать из текущего тарифа</span></label>
                    <select id="lot_tariff_plan" name="aLot[tariff_plan_id]">
                        <?php foreach ($aTariffPlans as $aTariffPlan):?>
                        <option rel="<?= $aTariffPlan['tariff_plan']; ?>" value="<?= $aTariffPlan['tariff_plan_id']; ?>" <?php if($oLot->tariff_plan_id == $aTariffPlan['tariff_plan_id']):?>selected="selected"<?php endif;?>><?= $aTariffPlan['name']; ?> #<?= $aTariffPlan['tariff_plan_id']; ?> (<?= $aTariffPlan['lots_left']; ?> заявок, заканчивается <?= $aTariffPlan['date_expired']; ?>)</option>
                        <?php endforeach;?>
                    </select>
                </div>
            </div>

            <div style="margin-top: 15px;">
                <div style="float: left; margin: 5px;">
                    Тип Заявки:
                </div>
                <div style="float: left; margin: 5px;">
                    <input id="lot_type_sale" type="radio" name="aLot[type]" value="sale" <?php if($oLot->type == 'sale'):?>checked="checked"<?php endif;?> />
                    <label for="lot_type_sale" class="inline"><span>Желаю продать</span></label>
                </div>
                <div style="float: left; margin: 5px;">
                    <input id="lot_type_purchase" type="radio" name="aLot[type]" value="purchase" <?php if($oLot->type == 'purchase'):?>checked="checked"<?php endif;?> />
                    <label for="lot_type_purchase" class="inline"><span>Желаю купить</span></label>
                </div>
                <div class="clear_both"></div>
            </div>

            <div style="margin-top: 15px;">
                <div style="float: left; margin: 5px;">
                    <label for="lot_amount" class="inline"><span>Сумма</span></label>
                    <input id="lot_amount" type="text" name="aLot[amount]" value="<?= $oLot->amount;?>" />
                </div>
                <div style="float: left; margin: 5px;">
                    <select name="aLot[currency]">
                        <?php foreach ($aCurrencies as $aCurrency):?>
                        <option value="<?= $aCurrency; ?>" <?php if($oLot->currency == $aCurrency):?>selected="selected"<?php endif;?>><?= Lot::getCurrencySymbol($aCurrency); ?></option>
                        <?php endforeach;?>
                    </select>
                </div>
                <div class="clear_both"></div>
            </div>

            <div style="margin-top: 15px;">
                <div style="float: left; margin: 5px;">
                    <label for="lot_desired_rate" class="inline"><span>Желаемый курс</span></label>
                    <input id="lot_amount" type="text" name="aLot[desired_rate]" value="<?= $oLot->desired_rate;?>" />
                </div>
                <div style="float: left; margin: 5px;">
                    <select name="aLot[desired_currency]">
                        <?php foreach ($aCurrencies as $aCurrency):?>
                        <option value="<?= $aCurrency; ?>" <?php if($oLot->desired_currency = 'BYR'):?>selected="selected"<?php endif;?>><?= Lot::getCurrencySymbol($aCurrency); ?></option>
                        <?php endforeach;?>
                    </select>
                </div>
                <div class="clear_both"></div>
            </div>

            <div style="margin-top: 15px;">
                <div style="margin: 5px;">
                    <label for="lot_placement_time" class="inline"><span>Срок размещения заявки</span></label>
                    <select id="lot_placement_time" name="aLot[placement_time]">
                        <?php foreach ($aPlacementTimesNames as $aPlacementTimesId => $aPlacementTimesName):?>
                        <option value="<?= $aPlacementTimesId; ?>" <?php if($aPlacementTimesId == 'seven_days'):?>selected="selected"<?php endif;?>><?= $aPlacementTimesName; ?></option>
                        <?php endforeach;?>
                    </select>
                </div>
            </div>

            <div style="margin-top: 15px;">
                <div style="margin: 5px;">
                    <label for="lot_bank" class="inline"><span>Ваш банк (код МФО)</span></label>
                    <input id="lot_bank" type="text" name="aLot[bank]" value="<?= $oLot->bank;?>" />
                </div>
            </div>

            <div style="margin-top: 15px;">
                <div style="margin: 5px;">
                    <input id="lot_is_urgent" type="checkbox" name="aLot[is_urgent]" value="1" <?php if($oLot->is_urgent == 1):?>checked="checked"<?php endif;?> />
                    <label for="lot_is_urgent" class="inline"><span>Срочная продажа</span></label>
                </div>
            </div>

            <div style="margin-top: 15px;">
                <div style="margin: 5px; float: left;">
                    <input type="submit" name="add_lot_submit" value="Добавить Заявку" />
                </div>
                <div style="margin: 5px; float: left;">
                    <a href="<?= Yii::app()->controller->createUrl('/profile/my_lots'); ?>">вернуться к списку заявок</a>
                </div>
                <div class="clear_both"></div>
            </div>

        </div>
    </form>

</div>

<script type="text/javascript">
    $(document).ready(function(){

        var checkTariffPlans = function(oTariffPlanSelect){
            if(oTariffPlanSelect.find('option:selected').attr('rel') == 'seller')
            {
                $('#lot_type_purchase').parent().hide();
            }
            else
            {
                $('#lot_type_purchase').parent().show();
            }
        };

        $('#lot_tariff_plan').change(function(){
            checkTariffPlans($(this));
        });

        checkTariffPlans($('#lot_tariff_plan'));

    });
</script>